package com.example.docmanagement.config;

import com.example.docmanagement.service.MinioService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MinIO 初始化配置
 * 应用启动时自动创建和配置 Buckets
 */
@Configuration
@Slf4j
@RequiredArgsConstructor
public class MinioInitializer {

    private final MinioService minioService;

    /**
     * 应用启动时初始化 MinIO Buckets
     */
    @Bean
    public CommandLineRunner initMinIO() {
        return args -> {
            log.info("开始初始化 MinIO Buckets...");
            try {
                minioService.initializeBuckets();
                log.info("MinIO Buckets 初始化完成");
            } catch (Exception e) {
                log.error("MinIO 初始化失败，请检查 MinIO 服务是否正常运行", e);
                log.error("MinIO 配置：192.168.1.86:9000，用户：esun");
                // 不抛出异常，允许应用继续启动（可选）
            }
        };
    }
}

